import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import AutoImport from "unplugin-auto-import/vite";
import UnoCSS from "unocss/vite";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    UnoCSS(),
    AutoImport({
      imports: ["vue", "vue-router"],
      eslintrc: {
        enabled: true,
      },
    }),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    // 自动导入的插件，解析器可以是 vant
    Components({
      dts: false,
      resolvers: [VantResolver({ importStyle: false })],
    }),
  ],
  server: {
    port: 5174,
    open: true,
    host: "0.0.0.0",
    proxy: {
      "/radar": {
        target: "http://222.128.81.162:8092", // 目标服务器
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/uploads/, "")
      },
      "/api/task": {
        target: "http://8.141.3.227:18081", // 目标服务器
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/task/, ""),
      },
      "/api": {
        target: "http://222.128.81.162:8090", // 目标服务器
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
